home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Apple II / Programming & Utilities / Apple IIgs APW Intro Prog Src / HP.PAS / EVENT.PAS.txt < prev    next >
Encoding:
Text File  |  1987-09-11  |  5.2 KB  |  189 lines

  1. UNIT Event;
  2.  
  3. {+----------------------------------------------------------------------------+
  4.  |                                                                            |
  5.  |         HodgePodge:  An example Apple IIGS Desktop application             |
  6.  |                                                                            |
  7.  |    Written in 65816 assembler and APW C by the Apple IIGS Tools Team       |
  8.  |              Translated to TML Pascal by TML Systems, Inc.                 |
  9.  |  Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS"  |
  10.  |                                                                            |
  11.  |             Copyright (c) 1986-87 by Apple Computer, Inc.                  |
  12.  |                Copyright (c) 1987 by TML Systems, Inc.                     |
  13.  |                                                                            |
  14.  |                     --------------------------------                       |
  15.  |                                                                            |
  16.  |     Pascal UNIT "EVENT.PAS" : Event loop and dispatching routine           |
  17.  |                                                                            |
  18.  +----------------------------------------------------------------------------+}
  19.  
  20.  
  21.  
  22. INTERFACE
  23.  
  24. USES
  25.        HPIntfData,         {HodgePodge Apple IIGS Toolbox Interface Units}
  26.        HPIntfProc,
  27.        HPIntfPdos,
  28.  
  29.        Globals,            {HodgePodge Code Units}
  30.        Dialog,
  31.        Font,
  32.        Paint,
  33.        Window,
  34.        Print,
  35.        Menu;
  36.  
  37.  
  38.  
  39. procedure MainEvent;   {Main event handling loop which repeats until Quit}
  40.  
  41.  
  42.  
  43. IMPLEMENTATION
  44.  
  45.  
  46.  
  47. procedure DisableItems;
  48.  
  49.    {Private routine to disable (dim) certain menu titles}
  50.  
  51.    begin   {of DisableItems}
  52.        DisableMItem (SaveAsItem);
  53.        DisableMItem (CloseItem);
  54.        DisableMItem (PrintItem);
  55.        DisableMItem (PageSetItem);
  56.    end;    {of DisableItems}
  57.  
  58.  
  59.  
  60. procedure EnableItems;
  61.  
  62.    {Private routine to enable (undim) certain menu titles}
  63.  
  64.    begin   {of EnableItems}
  65.        EnableMItem (SaveAsItem);
  66.        EnableMItem (CloseItem);
  67.        EnableMItem (PrintItem);
  68.        EnableMItem (PageSetItem);
  69.    end;    {of EnableItems}
  70.  
  71.  
  72.  
  73. procedure DisableAll;
  74.  
  75.    {Private routine to disable all menu titles for Desk Accessory (DA)}
  76.  
  77.    begin   {of DisableAll}
  78.        SetMenuFlag ($0080,EditMenuID);
  79.        DrawMenuBar;
  80.        DisableItems;
  81.    end;    {of DisableAll}
  82.  
  83.  
  84.  
  85. procedure SetUpForAppW;
  86.  
  87.    {Called if an application window (ours) is the frontmost window.
  88.     Private routine.}
  89.  
  90.    begin   {of SetUpForAppW}
  91.        SetMenuFlag ($0080,EditMenuID);
  92.        DrawMenuBar;
  93.        EnableItems;
  94.    end;    {of SetUpForAppW}
  95.  
  96.  
  97.  
  98. procedure SetUpForDAW;
  99.  
  100.    {Called if a Desk Accessory's window is the frontmost window. Private.}
  101.  
  102.    begin   {of SetUpForDAW}
  103.        DisableItems;
  104.        EnableMItem (CloseItem);
  105.        SetMenuFlag ($FF7F,EditMenuID);
  106.        DrawMenuBar;
  107.    end;    {of SetUpForDAW}
  108.  
  109.  
  110.  
  111. procedure CheckFrontW;
  112.  
  113.    {Check to whom the front window belongs to (us or a Desk Accessory (DA)),
  114.     and if it belongs to us, whether it is appropriate to disable (dim) certain
  115.     menu items (such as the Save item) or to enable them.  Private routine.}
  116.  
  117.    var theWindow    : GrafPortPtr;
  118.        myDataHandle : WindDataH;
  119.  
  120.    begin   {of CheckFrontW}
  121.        theWindow := FrontWindow;
  122.  
  123.        if theWindow = lastWindow then
  124.            Exit;
  125.    
  126.        if theWindow = nil then
  127.            DisableAll
  128.        else begin
  129.            if GetSysWFlag (theWindow) = true then
  130.                SetUpforDAW
  131.            else begin
  132.                SetUpforAppW;
  133.                myDataHandle := WindDataH (GetWRefCon (theWindow));
  134.                if myDataHandle^^.Flag = 1 then
  135.                    DisableMItem (SaveAsItem)
  136.            end;
  137.        end;
  138.  
  139.        lastWindow := theWindow;
  140.    end;    {of CheckFrontW}
  141.  
  142.  
  143.  
  144. procedure DoActivate;
  145.  
  146.    {If the Activate event is indeed an activate instead of a deactivate
  147.     then update menus based upon what the front window is.  Private routine.}
  148.  
  149.    begin   {of DoActivate}
  150.        if BitAnd (Event.wmModifiers,ActiveFlag) <> 0 then
  151.            CheckFrontW;
  152.    end;    {of DoActivate}
  153.  
  154.  
  155.  
  156. procedure MainEvent;
  157.  
  158.    {Main event handling routine which loops until the Done flag is set by
  159.     selection of the "Quit" item.  We call the Window Manager's TaskMaster
  160.     routine, which calls the Event Manager's GetNextEvent routine and
  161.     handles window resize tracking/resizing, window movement tracking/resizing,
  162.     window activiation (bringing to front by clicking on an inactive window),
  163.     among other things.  TaskMaster returns control to us when the user has
  164.     clicked a window's GoAway check box, or when the user has selected a menu
  165.     item, either with the mouse or with an equivalent Solid-Apple keystroke
  166.     sequence.}
  167.  
  168.    var code : integer;
  169.  
  170.    begin   {of MainEvent}
  171.        Event.wmTaskMask := $1FFF;  {Allow TaskMaster to do everything}
  172.        Done             := false;  {Done flag will be set by Quit item}
  173.  
  174.        repeat
  175.            CheckFrontW;
  176.            code := TaskMaster (-1,Event);
  177.            case code of
  178.                ActivateEvt : DoActivate;
  179.                wInGoAway   : DoCloseItem;
  180.                wInSpecial,
  181.                wInMenuBar  : DoMenu;
  182.            end;
  183.        until Done;
  184.    end;    {of MainEvent}
  185.  
  186.  
  187.  
  188. END.
  189.